package eoeProject.edenOfEast.page.account.accountDetailPage;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import eoeProject.edenOfEast.bean.EOEUserBean;
import eoeProject.edenOfEast.core.EOEAuthenticatedWebSession;
import eoeProject.edenOfEast.page.account.accountDetailPage.component.AccountDetailPanel;
import eoeProject.edenOfEast.utils.EOEUtils;

//@AuthorizeInstantiation({"ADMIN","USER"})
public class Index extends WebPage {
	private static final long serialVersionUID = 1L;

	private BookmarkablePageLink<WebPage> linkToTop = new BookmarkablePageLink<WebPage>(
			"linkToTop", eoeProject.edenOfEast.page.topPage.Index.class);
	private BookmarkablePageLink<WebPage> linkToTactics = new BookmarkablePageLink<WebPage>(
			"linkToTactics",
			eoeProject.edenOfEast.page.tactics.tacticsTop.Index.class);
	private BookmarkablePageLink<WebPage> linkToAnalyses = new BookmarkablePageLink<WebPage>(
			"linkToAnalyses",
			eoeProject.edenOfEast.page.analyses.analysesTop.Index.class);
	private BookmarkablePageLink<WebPage> linkToArchives = new BookmarkablePageLink<WebPage>(
			"linkToArchives",
			eoeProject.edenOfEast.page.archives.archivesTop.Index.class);
	private BookmarkablePageLink<WebPage> linkToLogin = new BookmarkablePageLink<WebPage>(
			"linkToLoginOrLogout",
			eoeProject.edenOfEast.page.loginPage.Index.class);
	private BookmarkablePageLink<WebPage> linkToLogout = new BookmarkablePageLink<WebPage>(
			"linkToLoginOrLogout",
			eoeProject.edenOfEast.page.logoutPage.Index.class);

	private static EOEUserBean userBean = new EOEUserBean();

	public Index(PageParameters parameters) {

		userBean = EOEUtils.getUserBean(parameters.get("userId").toInteger());

		AccountDetailPanel accountDetailPanel = new AccountDetailPanel(
				"accountDetailPanel", userBean);
		accountDetailPanel.setOutputMarkupId(true);
		add(accountDetailPanel);

		if (EOEAuthenticatedWebSession.get().isSignedIn()) {
			linkToLogout.add(new Label("linkToLoginOrLogoutLabel", "ログアウト"));
			add(linkToLogout.setOutputMarkupId(true));
		} else {
			linkToLogin.add(new Label("linkToLoginOrLogoutLabel", "ログイン"));
			add(linkToLogin.setOutputMarkupId(true));
		}
		add(linkToTop.setOutputMarkupId(true));
		add(linkToTactics.setOutputMarkupId(true));
		add(linkToAnalyses.setOutputMarkupId(true));
		add(linkToArchives.setOutputMarkupId(true));
	}
}
